﻿<?php

echo "<link rel='stylesheet' type='text/css' href='../css/avaliacao.css'>";

function DBExecute($query, $insertId = false){
	$result = mysqli_query($link, $query) or die(mysqli_error($link));
	
	if($insertId)
		$result = mysqli_insert_id($link);
	
	return $result;
}

function DBEscape($data){
	
	if(!is_array($data))
		$data = mysqli_real_escape_string($link, $data);
	else {
		$arr = $data;
		
		foreach ($arr as $key => $value){
			$key 	= DBEscape( $key );
			$value	= DBEscape( $value );
			
			$data[$key] = $value;
		}
	}
	
	DBClose($link);
	return $data;
}

function DBUpDate($table, array $data, $where = null, $insertId = false){
	foreach ($data as $key => $value){
		$fields[] = "{$key} = '{$value}'";
	}
	
	$fields = implode(', ', $fields);
	
	$table 	= DB_PREFIX.''.$table;
	$where	= ($where) ? " WHERE {$where}" : null;
	
	$query 	= "UPDATE {$table} SET {$fields}{$where}";
	return DBExecute($query, $insertId);
}

function DBCreate($table, array $data, $insertId = false){
		$data 	= DBEscape($data);
		
		$fields	= implode(', ', array_keys($data));
		$values = "'".implode("', '", $data)."'";
		
		$query 	= "INSERT INTO {$table} ( {$fields} ) VALUES ( {$values} )";
		
		return DBExecute($query, $insertId);
}

function DBRead($table, $where = null){
	$where = ($where) ? " {$where}" : null;
	
	$query 	= "SELECT * FROM {$table} {$where}";
	$result	= mysql_query($query);
	
	if(@mysql_num_rows($result)){
		while ($res = mysql_fetch_assoc($result)){
			$data[] = $res;
		
		$data = $data[0];
		return $data;
		}
	}else{
		return false;
	}
}

function professor($area = null,$aluno = null){
	if($area != null && $aluno != null){
		for($i = 1; $i <= 27; $i++){
			$prof = DBRead('professores',"WHERE id={$i} && area='{$area}'");
			for($j = 1; $j <= 15; $j++){
				$ver = DBRead('geral', "WHERE id={$j}");
				if($prof['id'] == $ver['id_prof']){
					if($ver['turma'] == $_SESSION['turma']){
						$pro = $prof['id'];
						if(!DBRead('controle',"WHERE id_prof={$pro} && id_aluno={$aluno}")){
							echo "<a href='#' rel='{$prof['id']}' class='lprof' title='{$prof['nome']}' name='{$prof['id']}' id='prof'><p>{$prof['nome']}</p></a>";
						}
					}
				}
			}
		}
	}
}
	
	
?>